package com.zheng.redpacket.server.config;

import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.TransportMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.concurrent.TimeUnit;

@Configuration
public class RedissonConfig {
    @Autowired
    Environment env;

    @Bean
    public RedissonClient config() {
        Config config = new Config();
        //设置传输模式为NIO，也可以设置成EPOLL等
        //config.setTransportMode(TransportMode.NIO);
        //设置redis节点的部署模式：单体、集群、主从、哨兵等
        /*config.useClusterServers()
                .addNodeAddress(env.getProperty("redisson.host.config")
                        , env.getProperty("redisson.host.config"));*/
        //单节点部署
        config.useSingleServer()
                .setAddress(env.getProperty("redisson.host.config"))
                .setKeepAlive(true);
        return Redisson.create(config);
    }
}
